home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 June: Reference Library / Dev.CD Jun 96 RL / Dev.CD Jun 96 RL.toast / Technical Documentation / develop / develop Issue 24 / develop Issue 24 code / Scriptable Database 1.0a15 / Database / DataRecord.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-19  |  5.9 KB  |  173 lines  |  [TEXT/CWIE]

  1.  
  2. #ifndef __DATARECORD__
  3. #define __DATARECORD__
  4.  
  5. //
  6. // For class TAbstractRecord
  7. //
  8. #include "AbstractRecord.h"
  9.  
  10. //
  11. //    Data Records:
  12. //
  13. //    Fields
  14. //
  15. //        Flag word
  16. //        Reference to owner
  17. //
  18. //        All following words contain data
  19. //
  20. //    Bits in flag word:
  21. //
  22. //        b31-b30:    Zero indicates a data record (Non-zero indicates a database record)
  23. //        b29-b24:    0x3F == a free block, anything else == a used block        
  24. //        b23-b16:    Encoded block physical size
  25. //        b15-b8:     Previous block's physical size (or 0 for first block in group)
  26. //         b7-b0:        Block size correction
  27. //
  28.  
  29. enum
  30. {
  31.     kDataFlags                        = 0,                // Flags stored in longword zero, as always
  32.     kDataOwnerReference                = 1,                // Reference to record that owns this data in longword 1
  33.     kHeaderSize                        = 8,                // Number of bytes in header == 2 longwords
  34.     kDataStorageStart                = 2,                // Real data starts at longword 2
  35.     kDataBlockSizeCorrection        = 0x000000FF,        // Physical size - sizeof(header) - size correction == length of data
  36.     kDataBlockSizeCorrectionShift    = 0,
  37.     kInitialDataBlockFlagsMask        = 0x00FFFFFF,        // Zero bits in this mask are used to clear bits in flag word when new data block is initialized
  38.     kInitialDataBlockFlagsWord        = 0                    // Temporary, to pass in when making a new record
  39. };
  40.  
  41. //================================================================================
  42. // Class TDataRecord
  43. //================================================================================
  44. class TDataRecord : public TAbstractRecord
  45. {
  46.     //
  47.     // ----- Fields --------------------------------------------------------------
  48.     //
  49. protected:
  50.     AConst<TDBProperty>                fDataOwner;
  51.     long                            fChangeImageSize;
  52.     Boolean                            fDataReleased;
  53.     long                            fOriginalRecordIndex;
  54.     
  55.     //
  56.     // ----- Methods -------------------------------------------------------------
  57.     //
  58.  
  59. public:
  60.                                     TDataRecord(TDatabaseDocument* doc, long recordIndex) :
  61.                                         TAbstractRecord(doc, recordIndex), fDataOwner(nil), fChangeImageSize(0), fDataReleased(false), fOriginalRecordIndex(recordIndex)
  62.                                         {
  63.                                             //
  64.                                             // Note:  we know that we never need a transaction pointer here
  65.                                             // because this object would already be constructed if its
  66.                                             // data had changed on some transaction.
  67.                                             //
  68.                                             // ◊Will this be true in the future, though?  Actually, fDataOwner
  69.                                             // might be a different record on a different transaction.  We
  70.                                             // should probably cache two completely different data owner
  71.                                             // objects, one for the active transaction, and one for the
  72.                                             // unchanged object.  Either that or look up the data owner each
  73.                                             // time it's needed (perhaps preferable)
  74.                                             //
  75.                                             fDataOwner = this->GetDBPropertyCursor(this->DataOwnerIndex(nil));
  76.                                         };
  77.     virtual                            ~TDataRecord();
  78.  
  79.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  80.     // Overrides of TTransactionAwareObject:
  81.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  82.  
  83.     virtual void                    PrepareToCommit(TTransaction* t);
  84.     virtual void                    CommitChanges(TTransaction* t);
  85.  
  86.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  87.     // Overrides of TAbstractRecord:
  88.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  89.  
  90. public:
  91.  
  92.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  93.     // Methods of TDataRecord:
  94.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  95.  
  96. protected:
  97.  
  98.     virtual const TDataRecord* DataRecord() const { return this; };
  99. //    virtual TDataRecord* DataRecord() const { return this; };
  100.     
  101.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  102.     // Public interface:  const methods
  103.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  104.  
  105. public:
  106.     long                            GetDataType(TTransaction* t) const;
  107.     long                            GetDataLength(TTransaction* t) const;
  108.     long                            MaximumDataLength(TTransaction* t) const;
  109.  
  110.     void                            GetTypedData(TTransaction* t, TAbstractDataReference& data) const;
  111.  
  112.     //
  113.     // Used by TDBProperty::Verify
  114.     //    
  115.     long                            DataOwnerIndex(TTransaction* t) const { return this->GetRecordData(t, kDataOwnerReference); }
  116.  
  117.     //
  118.     // Do debugging tests on this node
  119.     //
  120.     virtual void                    Verify(TTransaction* t, Boolean verifyDeep = false) const;
  121.     
  122.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  123.     // Public interface:  non-const methods
  124.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  125.  
  126. public:
  127.  
  128.     void                            ReleaseData(TTransaction* t);
  129.     void                            SetDataOwner(TTransaction* t, AnUpdate<TDBProperty> dataOwner);
  130.     
  131.     void                            SetTypedData(TTransaction* t, const TAbstractDataReference& data);
  132.  
  133.     //
  134.     // Usually, only a property record will ever create a data record
  135.     //
  136.     void                            InitializeNewDataRecord(TTransaction* t);
  137.     
  138.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  139.     // Protected interface:  const methods
  140.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  141.  
  142. protected:
  143.  
  144.     long                            BlockEncodedPhysicalSize(TTransaction* t) const;
  145.     long                            BlockPhysicalSize(TTransaction* t) const;
  146.     long                            SizeCorrection(TTransaction* t) const;
  147.     
  148.  
  149.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  150.     // Protected interface:  non-const methods
  151.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  152.  
  153. protected:
  154.  
  155.     void                            SetSizeCorrection(TTransaction* t, long sizeCorrection);
  156.     void                            SetBlockEncodedPhysicalSize(TTransaction* t, long blockPhysicalSize);
  157.     void                            SetLogicalSize(TTransaction* t, long logicalSize);
  158.  
  159.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  160.     // Private methods:
  161.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  162.  
  163. public:
  164.     
  165.     //
  166.     // Only to be called to do a comparison
  167.     //
  168.     TConstDataReference                DataReference(TTransaction* t) const;
  169.  
  170. };
  171.  
  172. #endif
  173.